package generics.selfreferential;

import java.lang.invoke.SerializedLambda;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.function.Function;

public abstract class AbstractWrapper<T, R, Children extends AbstractWrapper<T, R, Children>> extends Wrapper<T> {
    /**
     * 占位符
     */
    protected final Children typedThis = (Children) this;

    private T entity;

    @Override
    public T getEntity() {
        return entity;
    }


    public Children eq(boolean condition, R column, Object val) {
        printWriteReplace(column);
        return typedThis;
    }

    void printWriteReplace(Object lambda) {
        try {
            Method m = lambda.getClass().getDeclaredMethod("writeReplace");
            m.setAccessible(true);
            SerializedLambda sl = (SerializedLambda) m.invoke(lambda);
            System.out.println("方法名: " + sl.getImplMethodName());
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            System.out.println("没有 writeReplace 方法！");
        } catch (InvocationTargetException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }


}
